<?php

namespace CSService\Helper;

use Ke\Web\Form;
use Ke\Web\Html;

class SemanticUI extends Html
{

//	public $classButton       = 'a';
	public $classButtonReset  = 'ui button red';
	public $classButtonSubmit = 'ui button primary';
//	public $classA             = '';
//	public $classInputText     = 'input';
//	public $classInputPassword = '';
//	public $classInputRadio    = '';
//	public $classInputCheckbox = 'cccc';
//	public $classTextarea      = '';
//	public $classSelect        = '';

	public $classForm             = 'ui form';
	public $classFormField        = 'field';
	public $classFormInlineFields = 'inline fields';

	public $classInlineCheckbox   = 'field';
	public $classInlineRadio      = 'field';

	public function preInlineInputLabel(string $type, string $input, string $label)
	{
		$class = $this->preClass($this->getTagBaseClass('inline', $type));
		return "<div{$class}><div class='ui radio checkbox'>{$input}{$label}</div></div>";
	}

	public function mkFormColumn(string $field, $value = null, array $column = [], Form $form = null)
	{
		if (!isset($column['edit']))
			return '';
		$data = $this->preFormColumn($field, $value, $column);
		if ($data['type'] === 'hidden') {
			return $data['input'];
		}
		elseif ($data['type'] === 'checkbox' || $data['type'] === 'radio') {
			$fieldAttr = $this->fillTagBaseClass([
				'data-field-id' => $data['inputId'],
			], 'form', 'inline', 'fields');
			$error = $column['error'] ?? '';
			if (!empty($error)) {
//				$error = "<div class='ui red'>{$error}</div>";
				$fieldAttr['class'] = $this->joinClass($fieldAttr['class'] ?? '', 'error');
			}
			$fieldAttr = $this->attr($fieldAttr);

			return "<div{$fieldAttr}>{$data['label']}{$data['input']}</div>";
		}
		else {
			$fieldAttr = $this->fillTagBaseClass([
				'data-field-id' => $data['inputId'],
			], 'form', 'field');

			$error = $column['error'] ?? '';
			if (!empty($error)) {
//				$error = "<div class='ui red'>{$error}</div>";
				$fieldAttr['class'] = $this->joinClass($fieldAttr['class'] ?? '', 'error');
			}
			$fieldAttr = $this->attr($fieldAttr);

//			$labelClass = $this->preClass($this->getTagBaseClass('form', 'label'));
//			$inputClass = $this->preClass($this->getTagBaseClass('form', 'input'));
			return "<div{$fieldAttr}>{$data['label']}{$data['input']}</div>";
		}
	}

	public function mkFormRow(string $content, $isSubmit = false)
	{
		return $content;
	}

}